-
Notifications
You must be signed in to change notification settings - Fork 4
fix: multiple redirects throwing error when user not registered and n… #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…o error shown to user.
WalkthroughA React component was updated to prevent multiple redirects and alerts on authentication errors by introducing a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AuthLayout
participant Router
User->>AuthLayout: Renders component
AuthLayout->>AuthLayout: Checks for auth error
alt First error occurrence
AuthLayout->>AuthLayout: Set hasRedirected to true
AuthLayout->>User: Show alert with error message
AuthLayout->>Router: Redirect to root path
else Subsequent error occurrences
AuthLayout-->>AuthLayout: No action (redirect already occurred)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
platforms/blabsy/src/components/layout/auth-layout.tsx (1)
33-37
: Effective fix for multiple redirects with room for UX improvement.The logic correctly prevents multiple redirects by checking the ref flag before executing the redirect flow. Setting
hasRedirected.current = true
immediately prevents race conditions.Consider these improvements:
- Replace
alert()
with a proper toast notification for better UX- Consider if
hasRedirected
should be reset when the error is cleared and then occurs againFor better UX, consider replacing the alert with a toast notification:
- alert(error.message || 'An error occurred'); + // Use your preferred toast/notification library + showToast(error.message || 'An error occurred', 'error');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
platforms/blabsy/src/components/layout/auth-layout.tsx
(2 hunks)platforms/blabsy/src/lib/hooks/useRequireAuth.ts
(1 hunks)
🔇 Additional comments (3)
platforms/blabsy/src/lib/hooks/useRequireAuth.ts (1)
1-4
: LGTM! Formatting improvements for consistency.The changes standardize import formatting and quote styles without affecting functionality. This improves code consistency across the codebase.
Also applies to: 11-11
platforms/blabsy/src/components/layout/auth-layout.tsx (2)
1-1
: LGTM! Necessary import for the fix.Adding
useRef
to the imports is required for the multiple redirect prevention fix.
31-31
: LGTM! Good approach to track redirect state.Using
useRef
to track whether a redirect has already occurred is an effective solution to prevent multiple redirects. The boolean flag will persist across re-renders without causing additional renders.
…o error shown to user.
Description of change
multiple redirects throwing error when user not registered and no error shown to user.
Issue Number
Closes #276
Type of change
How the change has been tested
Manually.
Change checklist
Summary by CodeRabbit
Bug Fixes
Style